package com.swang.redis.service.facade;

import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.swang.redis.facade.RedisFacade;
import com.swang.redis.facade.rpc.CommonResult;
import com.swang.redis.facade.rpc.Result;
import com.swang.redis.facade.rpc.ResultFactory;
import com.swang.redis.service.handler.RedisHandler;

/**
 * @ClassName: JedisFacadeImpl
 * @Description: jedis对外暴露接口实现
 * @author swang
 * @date 2017年4月15日 下午3:41:33
 */
@Component(value="jedisFacadeImpl")
public class JedisFacadeImpl implements RedisFacade {
	
	@Resource(name="redisHandler")
	private RedisHandler redisHandler;

	@Override
	public CommonResult<String> get(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisHandler.get(key));
	}

	@Override
	public CommonResult<Set<String>> smembers(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisHandler.setAll(key));
	}

	@Override
	public CommonResult<Long> sadd(String key, String... value) {
		return ResultFactory.initCommonResultWithSuccess(redisHandler.setAdd(key, value));
	}

	@Override
	public Result set(String key, String value) {
		redisHandler.add(key, value);
		return ResultFactory.initResultWithSuccess();
	}

	@Override
	public Result expire(String key, int seconds) {
		redisHandler.expire(key, seconds);
		return ResultFactory.initResultWithSuccess();
	}

	@Override
	public CommonResult<Long> srem(String key, String... value) {
		return ResultFactory.initCommonResultWithSuccess(redisHandler.setDel(key, value));
	}

	@Override
	public CommonResult<Long> scard(String key) {
		return ResultFactory.initCommonResultWithSuccess(redisHandler.setCount(key));
	}

}
